/**
 * 
 */
package weibo4j.examples;

import java.util.List;

import weibo4j.Comments;
import weibo4j.Timeline;
import weibo4j.Users;
import weibo4j.examples.oauth2.Log;
import weibo4j.http.HttpClient;
import weibo4j.model.Comment;
import weibo4j.model.PostParameter;
import weibo4j.model.Status;
import weibo4j.model.StatusWapper;
import weibo4j.model.WeiboException;
import weibo4j.org.json.JSONArray;
import weibo4j.org.json.JSONObject;
import weibo4j.util.WeiboConfig;

/**
 * 微博主要接口
 * @author Administrator
 * 
 */
public class WeiboComment {
	
	//评论一条微博  comment_ori:当评论转发微博时，是否评论给原微博，0：否、1：是，默认为0。
	public static Comment comment(String access_token,String id,String message,int comment_ori){
		Timeline tm = new Timeline();
		tm.client.setToken(access_token);
		Comments cm = new Comments();
		cm.client.setToken(access_token);
		Comment comment = null;
		try {
			comment = cm.createComment(message,id,comment_ori);
			Log.logInfo(comment.toString());
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return comment;
	}
	//回复一条评论 
	public static Comment replay(String access_token,String id,String message,int comment_ori){
		Timeline tm = new Timeline();
		tm.client.setToken(access_token);
		Comments cm = new Comments();
		cm.client.setToken(access_token);
		Comment comment = null;
		try {
			comment = cm.createComment(message,id,comment_ori);
			Log.logInfo(comment.toString());
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return comment;
	}
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String access_token = WeiboContants.access_token;
		String uid =WeiboContants.uid;
		String domain =WeiboContants.domain;
		//send(access_token,"测试下微博自动挂机发布内容！要前后内容不一致");
		StatusWapper status=WeiboMessage.getLastedPublic(access_token,60);
		List l=status.getStatuses();
		for(int i=0;i<l.size();i++){
			Status s=(Status) l.get(i);
			comment(access_token,s.getId(),"蛇年春节,健康重要,平安第一,请关注我,转发我,评论我,@CTO沙龙俱乐部,@"+s.getUser().getName()+",即可参与春节后抽奖！ipad mini,iphone5,三星等手机!！"+i,1);
			try {
				Thread.sleep(100000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
	}

}
